package com.wanlink.mall.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkUtil {

    /**
     * 判断网络连接是否已开
     */
    public static boolean isNetworkAvailable(Context context) {
        boolean bisConnFlag = false;
        ConnectivityManager conManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo network = conManager.getActiveNetworkInfo();
        if (network != null) {
            bisConnFlag = conManager.getActiveNetworkInfo().isAvailable();
        }
        return bisConnFlag;
    }

    /**
     * wifi网络为true
     *
     * @return
     */
    public static boolean isWifi(Context context) {
        ConnectivityManager _cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo _ni = _cm.getActiveNetworkInfo();
        return _ni != null && _ni.getType() == ConnectivityManager.TYPE_WIFI;
    }
}
